//
//  AppleScriptObservation.m
//  Shion
//
//  Created by Chris Karr on 2/19/08.
//  Copyright 2008 Chris J. Karr. All rights reserved.
//

#import "AppleScriptObservation.h"


@implementation AppleScriptObservation

- (AppleScriptObservation *) init
{
	if (self = [super init])
		observation = [NSMutableDictionary dictionary];
	
	return self;
}

- (NSScriptObjectSpecifier *) objectSpecifier 
{
	NSArray * observations = [[NSApp delegate] valueForKey:@"observations"];

	NSUInteger index = NSNotFound;
	
	NSUInteger i = 0;
	for (i = 0; i < [observations count] && index == NSNotFound; i++)
	{
		AppleScriptObservation * asObservation = [observations objectAtIndex:i];
		
		if ([[asObservation name] isEqualToString:[self name]])
			index = i;
	}
	
    if (index != NSNotFound) 
	{
		NSScriptObjectSpecifier * containerRef = [NSApp objectSpecifier];

        return [[[NSIndexSpecifier alloc] initWithContainerClassDescription:[containerRef keyClassDescription] 
			containerSpecifier:containerRef key:@"observations" index:index] autorelease];
    }
	else
        return nil;
}

- (NSString *) name
{
	return [observation valueForKey:@"name"];
}

- (NSString *) value
{
	return [observation valueForKey:@"value"];
}

- (void) setName:(NSString *) name
{
	[observation setValue:name forKey:@"name"];
}

- (void) setValue:(NSObject *) value
{
	[observation setValue:value forKey:@"value"];
}

@end
